//
//  OSRecommendTagsViewController.m
//  百思不得姐
//
//  Created by PushMeBaby on 16/2/23.
//  Copyright © 2016年 CoderC. All rights reserved.
//

#import "OSRecommendTagsViewController.h"
#import "OSRecommendTag.h"
#import "OSRecommendTagCell.h"
@interface OSRecommendTagsViewController ()

@property (nonatomic,copy)NSArray *tags;


@end

@implementation OSRecommendTagsViewController

static NSString *const tagCellId = @"tagCellId";


- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
 
    
    [self setupTableView];

    [self loadTags];
    
    
}
-(void)setupTableView{
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    self.tableView.backgroundColor = OSGlobalBg;
    
    self.title = @"推荐标签";
    
    self.tableView.rowHeight = 80;
    
    [self.tableView registerNib:[UINib nibWithNibName:@"OSRecommendTagCell" bundle:nil] forCellReuseIdentifier:tagCellId];
    
}
-(void)loadTags{
    
    [SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeNone];
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"a"] = @"tag_recommend";
    params[@"action"] = @"sub";
    params[@"c"] = @"topic";
    
    
    [manager GET:OSHTTPURL parameters:params success:^(NSURLSessionDataTask *  task, id   responseObject) {
        
        self.tags = [OSRecommendTag objectArrayWithKeyValuesArray:responseObject];
        
        [self.tableView reloadData];
        
        [SVProgressHUD dismiss];
        
    } failure:^(NSURLSessionDataTask *  task, NSError *  error) {
        
        
        [SVProgressHUD showErrorWithStatus:@"加载数据失败"];
    }];
    
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.tags.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    OSRecommendTagCell *cell = [tableView dequeueReusableCellWithIdentifier:tagCellId ];
    
    // Configure the cell...
    
    cell.recommendTag = self.tags[indexPath.row];
    
    
    return cell;
}
@end
